<?php
/**
 * 代付
 *
 */
include './PayTool.php';
include './CryptDes.php';

$tool = new PayTool();
$params = initParams($tool);
echo $params['detail_data'];

$result = $tool->getResultWithUrl($tool->req_url, $params);
echo 'Req Data:'.$result.'</br>';

if($tool->checkResult($result)){
    $object = json_decode($result);
    if ($tool->resultSuccess($object)) {
        echo '<br>验签成功 返回结果 '.$result;
    } else {
        echo 'msg : '.$object->msg;
    }
}else{
    echo '<br>验签失败';
}
function initParams($tool){
    $merchant=$tool->merchantId;
    $sn = $tool->getSN($merchant);
//    请根据实际情况转码为 UTF-8
//    $subject = iconv('GB2312','UTF-8','****');
//    $params['subject'] = $subject;

    $params = array();
    $params['sn'] = $sn;
    $params['merchant'] = $merchant;
    $params['totalAmount'] = '0.01';
    $params['subject'] = '通用商户收款';
    $params['payType'] = 'quick';
    $params['remark'] = '代付';
    $params['callBack'] = $tool->callBack_url;
    $params['busiType'] = '100005';
    $params['version'] = '2.0';

    $desContMap = array();
    $desContMap['bankName'] = '中国建设银行';
    $desContMap['bankProvince'] = '广东省';
    $desContMap['bankCity'] = '深圳市';
    $desContMap['bankBranch'] = '深圳支行';
    $desContMap['bankAccountNo'] = '6217007200059431622';
    $desContMap['bankAccountName'] = '王小姐';
    $desContMap['bankAccountType'] = 'personal';//  对公：corporate 对私：personal
    $desContMap['bankCardType'] = 'debit';// 借记卡：debit 信用卡：credit

    $signMap = array();
    $signMap = array_merge($signMap, $params, $desContMap);

    $params['sign'] = $tool->sign($signMap, $tool->pay_key);
    $desContent = $tool->paramsToStr($desContMap);
    $des = new CryptDes($tool->des_key,'');
    $desResult = $des->encrypt($desContent);

//    echo '<br>desContent -- '.$desContent.'<br>desResult -- '.$desResult.'<br><br>';
    $params['detail_data'] = $desResult;
    return $params;
}


?>